package bTree.LeetCode;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class 最长的斐波那契子序列的长度 {
    public int lenLongestFibSubseq(int[] arr) {
        Set<Integer>set=new HashSet<>();
        for (int i : arr) {
            set.add(i);
        }
        int res=0;
        int length = arr.length;
        for (int i=0;i<length-1;i++){
            for (int j=i+1;j<length;j++){
                int path=0;
                int sum = arr[i] + arr[j];
                int pre=arr[j];
                while (set.contains(sum)){
                    path++;
                    int temp=sum;
                    sum=pre+sum;
                    pre=temp;
                }
                res=Math.max(res, path);
            }
        }
        return res==0?0:res+2;
    }
}